Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(time-select): [time-select] refactor the theme #2275

Merged
merged 5 commits into from
Oct 16, 2024
Merged

Conversation

Youyou-smiles
Copy link
Collaborator

@Youyou-smiles Youyou-smiles commented Oct 16, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Updated styles for the time select component, enhancing visual consistency and usability.
    • Introduced new variable names for improved clarity in styling.
  • Bug Fixes

    • Fixed height settings for the time select component and scrollbar for better layout stability.
    • Adjusted test cases to reflect the updated expected height for the 'small' size textbox.
  • Documentation

    • Updated naming conventions in CSS variables for easier reference and maintenance.

Copy link

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request focus on the time select component's styling, specifically in the index.less and vars.less files. Key modifications include the renaming of CSS variable functions, the introduction of new variable names, and the replacement of variable references with fixed values for certain styles. The height settings for the component and scrollbar have been adjusted, and various item styles have been explicitly defined. These updates aim to standardize the theming and improve consistency across the component's styles.

Changes

File Path Change Summary
packages/theme/src/time-select/... - Updated variable usage and fixed height settings in index.less.
- Renamed function from .component-css-vars-time-select() to .inject-TimeSelect-vars().
- Changed height references to fixed values and updated item styles with new variable names.
packages/theme/src/time-select/... - Modified variable declarations in vars.less to reflect new naming conventions and values.
- Removed certain variables and updated their references throughout the file.
examples/sites/demos/pc/app/time-select/... - Updated the expected CSS height for the 'small' size textbox in size-medium.spec.ts from 32px to 28px.

Possibly related PRs

Suggested reviewers

  • zzcr

🐇 In the land of styles, we hop and play,
With variables new, we brighten the day.
From fixed heights tall to colors that gleam,
Our time select shines, like a sweet dream!
So let’s celebrate with a joyful cheer,
For our code is now better, let’s give a big cheer! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 585744b and f57916d.

📒 Files selected for processing (2)
  • packages/theme/src/time-select/index.less (1 hunks)
  • packages/theme/src/time-select/vars.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/theme/src/time-select/index.less
  • packages/theme/src/time-select/vars.less

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the refactoring Refactoring (重构) label Oct 16, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (9)
packages/theme/src/time-select/vars.less (8)

15-15: Approved: Updated variable name and value.

The renaming of --ti-time-select-item-text-color to --ti-Time-Select-item-text-color aligns with the new naming convention. The use of var(--tv-color-act-primary-text) as the value may improve theme consistency.

Consider updating the comment to reflect the new naming convention:

// Time Select item text color

17-17: Approved: Updated variable name and value.

The renaming of --ti-time-select-item-font-size to --ti-Time-Select-item-font-size aligns with the new naming convention. The use of var(--tv-font-size-md) as the value may improve theme consistency.

Consider updating the comment to reflect the new naming convention:

// Time Select item font size

19-19: Approved: Updated variable name and value.

The renaming of --ti-time-select-item-padding-horizontal to --ti-Time-Select-item-padding-horizontal aligns with the new naming convention. The use of var(--tv-space-xl) as the value may improve theme consistency.

Consider updating the comment to reflect the new naming convention:

// Time Select item horizontal padding

21-21: Approved: Updated variable name and value.

The renaming of --ti-time-select-item-hover-bg-color to --ti-Time-Select-item-hover-bg-color aligns with the new naming convention. The use of var(--tv-color-bg-hover) as the value may improve theme consistency.

Consider updating the comment to reflect the new naming convention:

// Time Select item hover background color

23-23: Approved: Updated variable name and value.

The renaming of --ti-time-select-item-disabled-text-color to --ti-Time-Select-item-disabled-text-color aligns with the new naming convention. The use of var(--tv-color-text-disabled) as the value may improve theme consistency.

Consider updating the comment to reflect the new naming convention:

// Time Select item disabled text color

25-25: Approved with suggestions: Updated variable name and value.

The renaming of --ti-time-select-item-select-hover-bg-color to --ti-Time-Select-item-select-hover-bg-color aligns with the new naming convention. The use of var(--tv-color-bg-active) as the value may improve theme consistency.

  1. Consider updating the comment to reflect the new naming convention:
// Time Select selected item hover background color
  1. Consider renaming the variable to use "active" instead of "select" to match the value:
--ti-Time-Select-item-active-hover-bg-color: var(--tv-color-bg-active);

This would make the variable name more consistent with the value it's using.


27-27: Approved with suggestions: Updated variable name and value.

The renaming of --ti-time-select-item-selected-text-color to --ti-Time-Select-item-selected-text-color aligns with the new naming convention. The use of var(--tv-color-text-active) as the value may improve theme consistency.

  1. Consider updating the comment to reflect the new naming convention:
// Time Select selected item text color
  1. Consider renaming the variable to use "active" instead of "selected" to match the value:
--ti-Time-Select-item-active-text-color: var(--tv-color-text-active);

This would make the variable name more consistent with the value it's using.


Line range hint 1-29: Overall assessment: Improved theme consistency with minor suggestions.

The changes in this file consistently apply a new naming convention for variables and utilize more generic theme variables, which should improve overall theme consistency and maintainability.

To further improve the file:

  1. Update all comments to reflect the new naming convention (e.g., "Time Select" instead of "时间选择").
  2. Ensure comments accurately describe the purpose of each variable (especially for the content padding variable).
  3. Consider using "active" instead of "selected" or "select" in variable names where the corresponding value uses "active".
  4. Translate all comments to English for consistency with other comments in the codebase.

These minor adjustments will enhance the clarity and consistency of the theme variables.

packages/theme/src/time-select/index.less (1)

32-36: Approve variable name changes, but reconsider fixed values for line height and height.

The update to use new variable names prefixed with ti-Time-Select- is consistent with the refactoring effort and improves naming clarity. However, the use of fixed values for line height and height might reduce flexibility.

Consider using variables for line height and height:

- line-height: 32px;
- height: 32px;
+ line-height: var(--ti-Time-Select-item-line-height, 32px);
+ height: var(--ti-Time-Select-item-height, 32px);

This approach maintains consistency with other properties while allowing for easy theming and providing default values.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e2a5fba and 32625b0.

📒 Files selected for processing (2)
  • packages/theme/src/time-select/index.less (1 hunks)
  • packages/theme/src/time-select/vars.less (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
packages/theme/src/time-select/vars.less (1)

13-13: Improved function naming convention.

The renaming of the function from .component-css-vars-time-select() to .inject-Time-Select-vars() is a positive change. It follows a more consistent naming convention using PascalCase for the component name and accurately describes the action of injecting these variables into the global scope.

packages/theme/src/time-select/index.less (3)

40-41: Approve the updated variable names for selected, hover, and disabled states.

The changes to use new, more specific variable names for the selected, hover, and disabled states are consistent with the overall refactoring effort. These updates improve clarity and maintain a consistent naming convention throughout the component.

Also applies to: 45-45, 50-50


58-58: Approve the updated variable name for content padding.

The change to use the new variable name --ti-Time-Select-content-padding-top for the content's top padding is consistent with the overall refactoring effort. This update improves clarity and maintains a consistent naming convention.


21-21: Approve the updated CSS variable injection method.

The change from .component-css-vars-time-select() to .inject-Time-Select-vars() improves naming consistency and clarity. This appears to be part of a larger refactoring effort.

To ensure this change doesn't break other parts of the codebase, please run the following script:

✅ Verification successful

CSS variable injection method verified successfully.

The old method .component-css-vars-time-select is no longer present in the codebase, and the new method .inject-Time-Select-vars() is correctly defined in vars.less and used in index.less.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of the old method name

# Test: Search for the old method name. Expect: No results.
rg --type less "component-css-vars-time-select"

# Test: Verify the new method is defined. Expect: Definition found.
rg --type less "inject-Time-Select-vars"

Length of output: 230

--ti-time-select-scrollbar-height: 242px;
--ti-time-select-scrollbar-wrap-max-height: unset;
--ti-time-select-content-padding-top: var(--ti-common-space-2x, 8px);
--ti-Time-Select-content-padding-top: var(--tv-space-md);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Approved with suggestions: Updated variable name and value.

The renaming of --ti-time-select-content-padding-top to --ti-Time-Select-content-padding-top aligns with the new naming convention. The use of var(--tv-space-md) as the value may improve theme consistency.

The comment "面板高度" (panel height) is inconsistent with the variable's purpose, which is to set the top padding of the content.

  1. Update the comment to accurately reflect the variable's purpose:
// Time Select content top padding
  1. Consider translating the comment to English for consistency with other comments in the file.

Comment on lines +23 to +27
height: 242px;
.@{time-select-scrollbar-cls} {
height: var(--ti-time-select-scrollbar-height);
height: 242px;
.@{css-prefix}scrollbar__wrap {
max-height: var(--ti-time-select-scrollbar-wrap-max-height);
max-height: unset;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Reconsider using fixed height values and 'unset'.

The changes from variable references to fixed height values (242px) and 'unset' for max-height raise some concerns:

  1. Fixed values reduce flexibility and make it harder to maintain consistent theming across the application.
  2. The 'unset' value for max-height might affect the component's behavior in different contexts.

Consider reverting to using variables for these properties to maintain flexibility and consistency.

Suggested changes:

- height: 242px;
+ height: var(--ti-Time-Select-height, 242px);

- height: 242px;
+ height: var(--ti-Time-Select-scrollbar-height, 242px);

- max-height: unset;
+ max-height: var(--ti-Time-Select-scrollbar-wrap-max-height, none);

This approach allows for easy theming while providing default values.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
height: 242px;
.@{time-select-scrollbar-cls} {
height: var(--ti-time-select-scrollbar-height);
height: 242px;
.@{css-prefix}scrollbar__wrap {
max-height: var(--ti-time-select-scrollbar-wrap-max-height);
max-height: unset;
height: var(--ti-Time-Select-height, 242px);
.@{time-select-scrollbar-cls} {
height: var(--ti-Time-Select-scrollbar-height, 242px);
.@{css-prefix}scrollbar__wrap {
max-height: var(--ti-Time-Select-scrollbar-wrap-max-height, none);

// 时间选择选项字体色
--ti-time-select-item-text-color: var(--ti-common-color-text-primary, #191919);
--ti-Time-Select-item-text-color: var(--tv-color-act-primary-text);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个组件应该写成 --tv-TimeSelect

// 时间选择选项字体色
--ti-time-select-item-text-color: var(--ti-common-color-text-primary, #191919);
--tv-TimeSelect-item-text-color: var(--tv-color-act-primary-text);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不是像button那样的交互类组件,所以用这个变量是不准确的,应该用:--tv-color-text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring (重构)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants